/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.model.UserScoreRecord;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.UserScoreRecordService;
import com.yami.shop.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author lgh on 2018/10/16.
 */
@RestController
@Api(tags = "积分记录接口")
@RequestMapping("/p/score")
public class UserScoreController {
    @Autowired
    private UserScoreRecordService userScoreRecordService;
    @Autowired
    private UserService userService;

    /**
     * 获取积分记录
     */
    @GetMapping
    @ApiOperation(value = "获取积分记录", notes = "根据用户id获取")
    public ResponseEntity<List<UserScoreRecord>> put(@ApiParam(value = "记录类型 1支出 2收入") Integer type) {
        String userId = SecurityUtils.getUser().getUserId();
        LambdaQueryWrapper<UserScoreRecord> query = Wrappers.lambdaQuery(new UserScoreRecord())
                .eq(UserScoreRecord::getUid, userId)
                .eq(type != null, UserScoreRecord::getType, type)
                .orderByDesc(UserScoreRecord::getCreateTime);
        List<UserScoreRecord> list = userScoreRecordService.list(query);
        return ResponseEntity.ok(list);
    }
}
